-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add address arg for duckdb-server-rust #649
feat: add address arg for duckdb-server-rust #649
Conversation
let addr = SocketAddr::new( | ||
args.address | ||
.parse::<IpAddr>() | ||
.unwrap_or(Ipv4Addr::LOCALHOST.into()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this actually fall back since you define a default in line 26? I realize this might be a question for all the defaults here. It would be nice to define them only in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above default value (127.0.0.1
) will be used if nothing was passed.
The value in unwrap_or
(Ipv4Addr::LOCALHOST.into()
) will be used if parse
fails. For example, if an invalid IP address was passed like --address 127.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to define them only in one place.
I agree. Do you think using global constant variables a good way to achieve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about the parse failure case you described. I wonder whether we just want to fail when the parsing of provided or default values fails. That might make things simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made a change for that. Now, if --address
is not provided, it will use default value (only defined in one place), if invalid IP address is provided, it will output the error, not using the default value.
> ./target/release/duckdb-server --address 0.0.0.0 --port 5002
2025-01-09T19:30:34.343971Z INFO duckdb_server: Creating database in ':memory:'
2025-01-09T19:30:34.351430Z WARN duckdb_server: No keys for HTTPS found.
2025-01-09T19:30:34.351448Z INFO duckdb_server: DuckDB Server listening on http://0.0.0.0:5002 and ws://0.0.0.0:5002.
^C
> ./target/release/duckdb-server --port 5002
2025-01-09T19:30:38.984626Z INFO duckdb_server: Creating database in ':memory:'
2025-01-09T19:30:38.991219Z WARN duckdb_server: No keys for HTTPS found.
2025-01-09T19:30:38.991237Z INFO duckdb_server: DuckDB Server listening on http://127.0.0.1:5002 and ws://127.0.0.1:5002.
^C
> ./target/release/duckdb-server --address 999.999.999.999 --port 5002
error: invalid value '999.999.999.999' for '--address <ADDRESS>': invalid IP address syntax
For more information, try '--help'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Should we do the same for the app.rs file (e.g.
dp_path.unwrap_or(":memory:"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Added the default values as global constants.
Add
--address
as part of CLI arguments. The default is127.0.0.1
and if parsing the given value fails, it falls back toIpv4Addr::LOCALHOST